var str = "";
var strmix;
const utools = window.utools;
window.exports = {
	"sqlrefresh": {
		mode: "none",
		args: {
			enter: (action) => {
				utools.hideMainWindow()
				abc(action.payload,action.type);
				utools.outPlugin();
			}
		}
	}
}
function abc($date,$type) {
	//更新表名和字段名
	if($type=="regex"){
		strmix=window.localStorage.setItem("abc",$date);
		alert("字段名和表名更新成功");
		return;
	}
	//生成INSERT或UPDATE语句
	if(strmix=window.localStorage.getItem("abc")){
		var arr=strmix.split("\t");
		var tabname=arr.pop().split(":")[1];
		var da = $date.split("\r\n");
		if(da[0].indexOf("WHERE") != -1){
			//UPDATE	
			arr.push("");
			for(var i=0;i<da.length-1;i++){
				var ev=da[i].split("\t");
				str=str+"UPDATE "+tabname+" SET ";
				for(var j=0;j<arr.length;j++){
						if(j!=arr.length-1){
							str=str+arr[j]+"="+"'"+ev[j]+"'"+(j!=arr.length-2?",":"");
						}else{
							str=str+arr[j]+" "+ev[j];
						}
				}
				str=str+";\n"
			}
		}else{
			//INSERT
			for(var i=0;i<da.length-1;i++){
				var ev=da[i].split("\t");
				str=str+"INSERT INTO "+tabname+"("+arr+")VALUES(";
				for(var j=0;j<arr.length;j++){
					str=str+"'"+ev[j]+"'"+(j!=arr.length-1?",":"");
				}
				str=str+");\n"
				
			}
		}
		utools.copyText(str);
		str="";
	}else{
		alert("请先更新表名和字段名");
	}
}
